﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class KMrpt3 : BaseRptPage
{
    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);
        this.Load += new System.EventHandler(Page_Load);
    } 
    protected  void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            this.txtsdate.Text = DateTime.Now.ToString("yyyy-MM-01");
            this.txtedate.Text = DateTime.Now.ToString("yyyy-MM-dd");
            //this.GridView1.RowDataBound += new GridViewRowEventHandler(this.GridView_RowDataBound);
            //this.GridView1.Sorting += new  GridViewSortEventHandler(this.GridView_Sorting);
        }
    }
    protected override void GvBind()
    {
        string sortedField = GetSortedFields();
        int zt = 0;
        if (this.CheckBox1.Checked == true)
        {
            zt = 1;
        }
        else
        {
            zt = 0;
        }
        if (string.IsNullOrEmpty(sortedField))
        {
            sortedField = "orderid";
        }
        DataTable dt = db.DM_GetDateSet("exec KM_ShopWeekStructure_RPT '"
            + this.txtsdate.Text + "','" + this.txtedate.Text + "','','" + txtbigarea.Text + "','','',''," + zt + ",1").Tables[0];
        this.GridView1.DataSource = GridViewGroup.AddGurop(dt, "bigarea", "qty#invqty#lzv#xhl");
        this.GridView1.DataBind();
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        GvBind();
    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        this.GridView1.PageIndex = e.NewPageIndex;
        GvBind();
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        GridView1.AllowPaging = false;
        GvBind();
        GridViewToExcel(this.GridView1, "application/ms-excel", this.Title + ".xls");
        GridView1.AllowPaging = true;
    }
    protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
    {
        this.GridView_Sorting(sender, e);
    }
    protected void GridView1_DataBound(object sender, EventArgs e)
    {
        int index = -1;
        int startGroupIndex = 0;
        if (GridView1.Rows.Count == 0)
        {
            return;
        }
        foreach (GridViewRow row in GridView1.Rows)
        { 
            index++;
            if (index > 0 && (row.Cells[0].Text.ToString().Trim() == "" || row.Cells[0].Text.ToString().Trim() == "&nbsp;")) 
            { 
                row.Cells[0].Text = row.Cells[0].Text+" 小计";// GridView1.Rows[startGroupIndex].Cells[0].Text; 
                row.Attributes.Add("style", "background-color: #F2F2F2; font-weight: bold;font-variant: normal; color: #000000;"); 
                row.Attributes.Remove("onmouseout");
                row.Attributes.Remove("onmouseover");
                GridViewGroup.GroupRow(GridView1, index, 0, 2);
                GridViewGroup.GropCell(GridView1, 0, startGroupIndex, index - 1);
                startGroupIndex = index + 1;
            }
        }
        GridViewRow sumRow = GridView1.Rows[index];
        sumRow.Attributes.Add("style", "background-color: #EAEAEA;font-weight: bold;font-variant: normal;color: #000000;");
        sumRow.Attributes.Remove("onmouseout");
        sumRow.Attributes.Remove("onmouseover");
        GridViewGroup.GroupRow(GridView1, index, 0, 2);
    }
}